﻿using System;
using System.Globalization;
using NUnit.Framework;
using ValidationFramework.WPF;

namespace ValidationFramework.Tests.WPF
{
    public class EnumValueConverterTest
    {

        public enum Numbers
        {
            One,
            Two,
            Three
        }
        [TestFixture]
        public class Convert
        {

            [Test]
            public void True()
            {
                var enumValueConverter = new EnumValueConverter();
                Assert.IsTrue((bool)enumValueConverter.Convert("One", typeof(bool), "One", CultureInfo.CurrentCulture));
            }

            [Test]
            [ExpectedException(typeof(ArgumentException))]
            public void ExceptionNotBoolTrue()
            {
                var enumValueConverter = new EnumValueConverter();
                enumValueConverter.Convert("One", typeof(int), "One", CultureInfo.CurrentCulture);
            }

            [Test]
            public void NullableBool()
            {
                var enumValueConverter = new EnumValueConverter();
                Assert.IsTrue((bool)enumValueConverter.Convert("One", typeof(bool?), "One", CultureInfo.CurrentCulture));
            }

            [Test]
            public void False()
            {
                var enumValueConverter = new EnumValueConverter();
                Assert.IsFalse((bool)enumValueConverter.Convert("One", typeof(bool), "Two", CultureInfo.CurrentCulture));
            }

        }


        [TestFixture]
        public class ConvertBack
        {

            [Test]
            public void Simple()
            {
                var enumValueConverter = new EnumValueConverter();
                Assert.AreEqual(Numbers.Two, (Numbers)enumValueConverter.ConvertBack(true, typeof(Numbers), "Two", CultureInfo.CurrentCulture));
            }

            [Test]
            public void SimpleNullable()
            {
                var enumValueConverter = new EnumValueConverter();
                Assert.AreEqual(Numbers.Two, (Numbers)enumValueConverter.ConvertBack(true, typeof(Numbers?), "Two", CultureInfo.CurrentCulture));
            }

            [Test]
            [ExpectedException(typeof(ArgumentException))]
            public void ExceptionValueNotFound()
            {
                var enumValueConverter = new EnumValueConverter();
                enumValueConverter.ConvertBack(true, typeof(Numbers?), "Four", CultureInfo.CurrentCulture);
            }

            [Test]
            [ExpectedException(typeof(ArgumentException))]
            public void ExceptionInvalidType()
            {
                var enumValueConverter = new EnumValueConverter();
                enumValueConverter.ConvertBack(true, typeof(int), "Two", CultureInfo.CurrentCulture);
            }



        }
    }
}
